package kt_test.room.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import kt_test.room.dao.*
import kt_test.room.entity.*

@Database(entities = [UserInfoEntity::class, OxygenSampleEntity::class], version = 1,exportSchema = false)
abstract class OxygenDatabase : RoomDatabase() {
    abstract fun userInfoDao(): UserInfoDao
    abstract fun oxygenSampleDao(): OxygenSampleDao

    companion object {
        @Volatile private var INSTANCE: OxygenDatabase? = null

        fun getDatabase(context: Context): OxygenDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    OxygenDatabase::class.java,
                    "oxygen_database"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}
